package com.kxmall.web.controller.rider;

import cn.dev33.satoken.annotation.SaIgnore;
import com.kxmall.common.core.controller.BaseRiderController;
import com.kxmall.common.core.domain.R;
import com.kxmall.common.utils.IpUtil;
import com.kxmall.rider.domain.vo.KxRiderOrderVo;
import com.kxmall.rider.domain.vo.KxRiderVo;
import com.kxmall.rider.domain.vo.RiderLoginDTO;
import com.kxmall.rider.domain.vo.RiderWxDTO;
import com.kxmall.web.controller.rider.service.RiderInfoService;
import com.kxmall.web.controller.rider.service.RiderWxLoginService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author kaixin
 * @version 1.0
 * @date 2023/9/23
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/rider/app")
public class RiderController extends BaseRiderController {

    private final RiderInfoService riderInfoService;

    /**
     * 配送员开工
     *
     * @return 结果
     */
    @GetMapping("/toWorking")
    public R<String> toWorking() {
        Long riderId = getRiderLoginUser().getUserId();
        return R.ok(riderInfoService.toWorking(riderId));
    }

    /**
     * 配送员休息
     *
     * @return 结果
     */
    @GetMapping("/toRest")
    public R<String> toRest() {
        Long riderId = getRiderLoginUser().getUserId();
        return R.ok(riderInfoService.toRest(riderId));
    }

    /**
     * 配送员休息
     *
     * @return 结果
     */
    @GetMapping("/getWorkingState")
    public R<RiderLoginDTO> getWorkingState() {
        Long riderId = getRiderLoginUser().getUserId();
        return R.ok(riderInfoService.getWorkingState(riderId));
    }

    /**
     * 账号密码登录
     *
     * @return 结果
     */
    @SaIgnore
    @GetMapping("/loginRider")
    public R<RiderLoginDTO> loginRider(String phone, String password, String ip) {
        return R.ok(riderInfoService.loginRider(phone, password, ip));
    }


    /**
     * 更改配送员下属车辆位置信息
     */
    @PostMapping("/updateAddress")
    public R<String> updateAddress(@RequestBody KxRiderOrderVo riderOrderVo) {
        return R.ok(riderInfoService.updateAddress(riderOrderVo));
    }
}
